package com.example.lanouhn.bantangapp.activities.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.lanouhn.bantangapp.R;
import com.example.lanouhn.bantangapp.activities.contants.TogLine;
import com.example.lanouhn.bantangapp.activities.contants.TogUser;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lanouhn on 16/7/19.
 */
public class Adapter_TogLine extends RecyclerView.Adapter<Adapter_TogLine.MyViewHolder> {
    private Context context;
    List<TogLine> list;

    public Adapter_TogLine(Context context, List<TogLine> list) {
        this.context = context;
        this.list = list;

    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.line_item,null);
        MyViewHolder viewHolder = new MyViewHolder(view);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(final MyViewHolder holder, final int position) {

        holder.title.setText(list.get(position).getTitle());
        holder.desc.setText(list.get(position).getDesc());
        holder.price.setText(list.get(position).getPrice());
        holder.likes.setText(list.get(position).getLikes());
        //图片
        Picasso.with(context).load(list.get(position).getPic()).into(holder.image);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        private TextView  title;
        private TextView  desc;
        private TextView  price;
        private TextView  likes;
        private ImageView image;

        public MyViewHolder(View itemView) {
            super(itemView);
            title= (TextView) itemView.findViewById(R.id.title);
            desc= (TextView) itemView.findViewById(R.id.desc);
            price= (TextView) itemView.findViewById(R.id.price);
            likes= (TextView) itemView.findViewById(R.id.likes);
            image= (ImageView) itemView.findViewById(R.id.image);


        }
    }
}
